package com.youlian.utils;


import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.youlian.activity.R;
import com.youlian.utils.interfaces.DialogListener;


public class DialogViewer {

	private Context context;
	private Dialog dialog;
	private LayoutInflater layoutInflater;
	private LinearLayout linearlayout;
	private TextView textView;
	private Button ok, cancel;
	private String string;
	private DialogListener dialogListener;

	public DialogViewer(Context context, String string, DialogListener dialogListener) {
		this.context = context;
		this.dialogListener = dialogListener;
		this.string = string;
	}

	public void create() {
		layoutInflater = LayoutInflater.from(context);
		linearlayout = (LinearLayout) layoutInflater.inflate(
				R.layout.more_updata_psd_pop, null);
		dialog = new Dialog(context, R.style.dialog);
		dialog.getWindow().setContentView(linearlayout);
//		textView = (TextView) dialog.findViewById(R.id.textView);
//		if (string != null) {
//			textView.setText(string);
//		}
		ok = (Button) dialog.findViewById(R.id.ok);
		cancel = (Button) dialog.findViewById(R.id.cancel);
		ok.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialogListener.onFinish(dialog);
			}
		});

		cancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialogListener.onCancel(dialog);
			}
		});
		if (!dialog.isShowing()) {
			dialog.show();
		}
	}

	public void dismiss() {
		if (dialog != null && dialog.isShowing()) {
			dialog.dismiss();
		}
	}
}
